package com.jzr.medical.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jzr.common.BaseController;
import com.jzr.common.entity.vo.Result;
import com.jzr.common.util.U;
import com.jzr.medical.db1.model.TCareLabel;
import com.jzr.medical.db1.service.CareLabelService;
import com.jzr.medical.db1.vo.CareLabelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/careLabel")
public class CareLabelController extends BaseController {
    @Autowired
    CareLabelService careLabelService;

    @GetMapping("/codeList")
    public Result<List<TCareLabel>> codeList(){
        QueryWrapper<TCareLabel> qw = new QueryWrapper<>();
        qw.select("id,label_code,label_name,bg_color,font_color");
        qw.orderByAsc("sort");
        qw.eq(TCareLabel.Status_,1);

        List<TCareLabel> list = careLabelService.list(qw);
        return Result.success("成功",list);
    }

    @GetMapping("/list")
    public Result<List<CareLabelVo>> list(TCareLabel record){
        QueryWrapper<CareLabelVo> qw = new QueryWrapper<>();
        qw.orderByAsc("sort");
        List<CareLabelVo> list = careLabelService.list(qw);
        return Result.success("成功",list);
    }

    @PostMapping("/add")
    public Result<CareLabelVo> add(CareLabelVo record){
        record.setStatus(1);
        CareLabelVo result = careLabelService.saveAndGet(record);
        return Result.success("成功",result);
    }

    @GetMapping("/delete")
    public Result<Boolean> delete(TCareLabel record){
        Boolean rt = careLabelService.removeById(record.getId());
        return Result.success("成功",rt);
    }

    @PostMapping("/update")
    public Result<CareLabelVo> update(CareLabelVo record){
        CareLabelVo rt = careLabelService.updateAndGet(record);
        return Result.success("成功",rt);
    }
    @PostMapping("/save")
    public Result<CareLabelVo> save(CareLabelVo record){
        if(!U.isBlank(record.getId())){
            return this.update(record);
        }else{
            return this.add(record);
        }
    }
    @PostMapping("/saveBatch")
    public Result<List<CareLabelVo>> saveBatch(@RequestBody List<CareLabelVo> list){
        List<CareLabelVo> result = careLabelService.saveBatch(list);
        return Result.success("成功",result);
    }
}
